<template>
  <div>
    <el-dialog title="用户信息" :visible.sync="show" width="70%" append-to-body>
      <div>
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="用户账号" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入用户账号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="用户昵称" prop="nickName">
            <el-input
              v-model="queryParams.nickName"
              placeholder="请输入用户昵称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
            >
              搜索
            </el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
              重置
            </el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
        </el-row>
        <el-table v-loading="loading" :data="dataList" border stripe>
          <el-table-column label="#" type="index" width="80" align="center">
            <template slot-scope="scope">
              <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="头像" align="center" width="100">
            <template slot-scope="scope">
              <div v-if="scope.row.avatar">
                <img
                  :src="baseUrl + scope.row.avatar"
                  style="width: 50px; height: 50px; border-radius: 50%"
                />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="用户账号" align="center" prop="userName" width="120" />
          <el-table-column label="用户昵称" align="center" prop="nickName" />
          <el-table-column label="用户类型" align="center" width="120">
            <template slot-scope="scope">
              <el-tag
                :type="
                  scope.row.memberType == 1
                    ? 'success'
                    : scope.row.memberType == 2
                    ? 'danger'
                    : 'info'
                "
                effect="plain"
              >
                {{
                  scope.row.memberType == 1
                    ? "充电/停车"
                    : scope.row.memberType == 2
                    ? "停车"
                    : "临时用户"
                }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="会员类型" align="center" width="120">
            <template slot-scope="scope">
              <el-tag
                :type="
                  scope.row.vipType == 1
                    ? 'success'
                    : scope.row.vipType == 2
                    ? 'warning'
                    : scope.row.vipType == 3
                    ? 'danger'
                    : 'info'
                "
                effect="plain"
              >
                {{
                  scope.row.vipType == 1
                    ? "月卡"
                    : scope.row.vipType == 2
                    ? "季卡"
                    : scope.row.vipType == 3
                    ? "年卡"
                    : scope.row.memberType == 3
                    ? "非会员"
                    : "已过期"
                }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="帐号状态" align="center" width="120">
            <template slot-scope="scope">
              <el-tag :type="scope.row.status == 1 ? 'success' : 'info'" effect="plain">
                {{ scope.row.status == 1 ? "启用" : "禁用" }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="用户余额(元)"
            align="center"
            prop="wallet"
            width="120"
          />
          <el-table-column label="停车点位" align="center" prop="areaName" width="180" />
          <el-table-column label="单元号" align="center" prop="unitNo" width="180" />
          <el-table-column label="备注" align="center" prop="remark" />
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleCancel">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMember } from "@/api/weiriya/member";
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    // 停车点位ID
    id: {
      type: String,
      default: "",
    },
  },
  computed: {
    show: {
      get() {
        return this.value;
      },
      set() {
        this.$emit("input", false);
      },
    },
  },
  watch: {
    value(val) {
      if (val) {
        this.queryParams.areaId = this.id;
        this.getList();
      }
    },
  },
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      loading: false, // 加载状态
      showSearch: true, // 显示搜索条件
      total: 0, // 总条数
      dataList: [], // 数据列表
      queryParams: {
        // 查询参数
        pageNum: 1,
        pageSize: 10,
        areaId: null,
        userName: null,
        nickName: null,
      },
    };
  },
  methods: {
    // 获取数据
    getList() {
      this.loading = true;
      listMember(this.queryParams)
        .then((response) => {
          this.dataList = response.rows;
          this.total = response.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 搜索
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 关闭弹窗
    handleCancel() {
      this.show = false;
    },
  },
};
</script>

<style lang="scss" scoped></style>
